#include<bits/stdc++.h>
using namespace std;
string dizhi[10];
int main(){
	freopen("network.in", "r", stdin);
	freopen("network.out", "w", stdout);
	int n;
	cin >> n;
	while(n --){
		for(int i = 1; i <= 5; i ++)
		    dizhi[i] = "";
		string op, ad;
		int t = 1;
		cin >> op >> ad;
		for(int i = 0; i < ad.size(); i ++){
			if(ad[i] != '.' && ad[i] != ':') dizhi[t] += ad[i];
			else t ++;
		}
		cout << dizhi[1].size() << endl;
	}
	return 0;
}

